//
//  FindeDeatilTableViewCell.m
//  XWZ_News_Work
//
//  Created by penngshi on 16/1/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "FindeDeatilTableViewCell.h"
//@property (nonatomic , strong) UILabel *nameLabel;
//@property (nonatomic , strong) UILabel *nameValueLabel;
//@property (nonatomic , strong) UILabel *cententLabel;
//@property (nonatomic , strong) UIButton *bigButton;
//@property (nonatomic , strong) FinfModel *findeModel;
@implementation FindeDeatilTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}
+ (CGFloat)heightWithStr:(NSString *)str
{
    CGRect frame = [str boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 100, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18.0] forKey:NSFontAttributeName]context:nil];
    
    
    return frame.size.height;
}

- (void)createSubView
{
//    self.backgroundColor = [UIColor redColor];
    self.headerView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
//     self.headerView.backgroundColor = [UIColor blackColor];
    self.headerView.layer.masksToBounds = YES;//裁掉边界
    self.headerView.layer.cornerRadius = 25;//设置半径
    [self.contentView addSubview:self.headerView];
    
    
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.headerView.frame.size.width + self.headerView.frame.origin.x + 20, self.headerView.frame.origin.y, SCREEN_WIDTH - self.headerView.frame.size.width + self.headerView.frame.origin.x  - 40, 20)];
    self.nameLabel.font = [UIFont systemFontOfSize:15.0];
//    self.nameLabel.backgroundColor = [UIColor brownColor];
    [self.contentView addSubview:self.nameLabel];
    
    
    
    self.nameValueLabel  = [[UILabel alloc]initWithFrame:CGRectMake(self.nameLabel.frame.size.width + self.nameLabel.frame.origin.x + 10, self.headerView.frame.origin.y, 80, 20)] ;
       self.nameValueLabel.font = [UIFont systemFontOfSize:15.0];
//    self.nameValueLabel.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.nameValueLabel];
    
    
    
    self.cententLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x, self.headerView.frame.origin.y + self.nameValueLabel.frame.size.height + 10, SCREEN_WIDTH - self.nameLabel.frame.origin.x - 20, 50)];
//    self.cententLabel.backgroundColor = [UIColor blueColor];
    self.cententLabel.numberOfLines = 0;
    [self.contentView addSubview:self.cententLabel];
    
    UIImage *rightImage =  [UIImage imageNamed:@"iconfont-xialaanniu"];
    //    图片渲染模式
    rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *rightImage1 =  [UIImage imageNamed:@"shangla (2)"];
    //    图片渲染模式
    rightImage1 = [rightImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.bigButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.bigButton.frame = CGRectMake( self.cententLabel.frame.origin.y + self.cententLabel.frame.size.width / 2, self.cententLabel.frame.origin.y + self.cententLabel.frame.size.height +  30, 50, 10);
//    self.bigButton.backgroundColor = [UIColor redColor];
    [self.bigButton setImage:rightImage forState:UIControlStateNormal];
    [self.bigButton setImage:rightImage1 forState:UIControlStateSelected];
    [self.bigButton addTarget:self action:@selector(listButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.bigButton];
    
    
    self.nameLabel.textColor = [UIColor grayColor];
    self.nameValueLabel.textColor = [UIColor grayColor];
    self.cententLabel.textColor = [UIColor grayColor];
}
- (void)listButtonAction:(UIButton  *)sender
{
    if (sender.selected == NO) {
        
        CGFloat height = [[self class] heightWithStr:self.cententLabel.text];
        //    先保存label的坐标及宽度信息
        CGRect frameL = self.cententLabel.frame;
        frameL.size.height = height ;
        self.cententLabel.frame = frameL;
        self.cententLabel.numberOfLines = 0;
        [self.delegate TrunCellHeight];
        self.bigButton.frame = CGRectMake( self.cententLabel.frame.origin.y + self.cententLabel.frame.size.width / 2, self.cententLabel.frame.origin.y + self.cententLabel.frame.size.height +  10, 50, 10);

    } else
    {
        self.cententLabel.frame = CGRectMake(self.nameLabel.frame.origin.x, self.headerView.frame.origin.y + self.nameValueLabel.frame.size.height + 10, SCREEN_WIDTH - self.nameLabel.frame.origin.x - 20, 50);
        self.cententLabel.numberOfLines = 0;
        self.bigButton.frame = CGRectMake( self.cententLabel.frame.origin.y + self.cententLabel.frame.size.width / 2, self.cententLabel.frame.origin.y + self.cententLabel.frame.size.height +  10, 50, 10);
//        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, 150);
        [self.delegate1 ReturnCellHeight];
    }
    
    sender.selected =! sender.selected;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
